<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">

</head>
<body  >
<div class="layui-container">


    <form class="layui-form">
        <div class="layui-row">
            <div class="layui-col-md12">

                <fieldset class="layui-elem-field" style="margin-top: 20px;">
                    <legend>生成零散订单</legend>


                    <div class="layui-form-item">

                        <div class="layui-inline">
                        <label class="layui-form-label"><span style="color: red;">*</span>订单日期 </label>
                        <div class="layui-input-inline" style="width: 150px;">
                            <input   type="text" name="ddrq"  required lay-verify="required" placeholder="请输入"  class="layui-input" id="ddrq" >
                        </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;"><span style="color: red;">*</span>订单状态</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <select name="ddzt" required lay-verify="required"  >
                                    <option value=""></option>
                                    <option value="待发布">待发布</option>
                                    <option value="已发布">已发布</option>
                                    <option value="已完成">已完成</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                        <label class="layui-form-label" style="width: 70px;"><span style="color: red;">*</span>客户简称</label>
                        <div class="layui-input-inline" style="width: 150px;">
                            <div class="layui-input-inline layui-form" style="width: 150px;">

                                <select name="khid" lay-verify="required" required lay-search   id="khjc"  lay-filter="khjc"	 style="width: 150px;" >
                                    <option value="">搜索选择</option>
                                </select>
                            </div>
                        </div>
                        </div>
                        <div class="layui-inline">
                        <label class="layui-form-label" style="width: 70px;"><span style="color: red;">*</span>区域名称</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <select name="qyid"   lay-search lay-verify="required" required  id="qymc"  style="width: 150px;" lay-filter="qymc"	 >
                                    <option value="">搜索选择</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">



                        <label class="layui-form-label" > <span style="color: red;">*</span>线路名称</label>
                        <div class="layui-input-inline" style="width: 430px;">
                            <input   type="hidden" name="xlmc" id="xlmcHid" >
                        <select name="xlid"   lay-search  id="xlmc"    lay-filter="xlmc" lay-verify="required" required >
                            <option value="">搜索选择</option>
                        </select>
                         </div>



                        <div class="layui-inline"  >
                            <label class="layui-form-label" style="width: 78px;" >货物</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input   type="text" name="huowu"      class="layui-input" id="huowu" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 71px;">货物数量</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input   type="text" name="hwsl"      class="layui-input" id="hwsl"  >
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">





                        <div class="layui-inline">
                            <label class="layui-form-label">运费</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input   type="text" name="yunfei"     class="layui-input" id="yunfei" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;">公里数</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="gls" class="layui-input" id="gls" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;">油单价</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="ydj" class="layui-input" id="ydj" >
                            </div>
                        </div>
                    </div>






                </fieldset>
            </div>
        </div>


        <button id="modiSub" class="layui-btn layui-btn-normal "  lay-submit lay-filter="new" style="width: 10%; position: absolute;left: 45%"  >立即提交</button>
    </form>
</div>
<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script src="../js/tools.js"></script>

<script>
    layui.use(['table','form','layer','laydate','upload'],function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.$;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var upload = layui.upload;
        //校验
        judgments($,["yunfei","gls","ydj","bglyh","llcyje","sfl","hcssl","sjyf","shje","ddf","sjgls","usje","ssje","ysje","hwsl"],/^([1-9]\d*|0)(\.\d{1,2})?$/,"请输入整数或小数");
        judgment($,'jsysj',/^\d{11}$/,"请输入正确的手机号码");

//提交
        $("#modiInfo").on('click',function(){
            $("#huowu,#hwsl,#yunfei,#gls,#ydj").addClass("layui-disabled");
            $("#huowu,#hwsl,#yunfei,#gls,#ydj").attr("disabled",true);

            $("#modiSub").removeClass("layui-btn-disabled");
            $("#modiSub").removeAttr("disabled");

            $("#modiInfo").addClass("layui-btn-disabled");
            $("#modiInfo").attr("disabled",true);

            form.render('select');
        });


        laydate.render({
            elem: '#ddrq' //指定元素
            ,theme:'#0099FF'
            ,value: getFormatDate()
            ,type: 'date'
            ,format:'yyyy-MM-dd'
        });
//渲染客户
        $.ajax({
            url: contextPath+"/cstmr",
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {

                for(var i in res.list){

                    var option = "<option value='"+ res.list[i].khid+ "'>"+res.list[i].khjc+"</option>";

                    $("#khjc").append(option);
                };
                form.render('select');
            }

        });
//区域
        form.on('select(khjc)', function (data) {
            $("#qymc").empty() ;
            $.ajax({
                url: contextPath+"/area/"+data.value,
                type: "GET",
                contentType:"application/json;charset=utf-8",
                dataType:"json",
                success: function(res) {
                    console.log(res);
                    $("#qymc").append("<option value=''>请选择</option>");
                    for(var i in res.list){

                        var option = "<option value='"+ res.list[i].qyid+ "'>"+res.list[i].qymc+"</option>";

                        $("#qymc").append(option);
                    };
                    form.render('select');
                }
            });
        });
//线路
        form.on('select(qymc)', function (data) {


            console.log(data.value);
            $("#xlmc").empty() ;
            $.ajax({
                url: contextPath+"/area/info/"+data.value,
                type: "GET",
                contentType:"application/json;charset=utf-8",
                dataType:"json",
                success: function(res) {
                    $.ajax({
                        url: contextPath+"/road?qymczj="+res.qymc,
                        type: "GET",
                        contentType:"application/json;charset=utf-8",
                        dataType:"json",
                        success: function(res) {
                            $("#xlmc").append("<option value=''>请选择</option>");
                            console.log(res);
                            for(var i in res.list){

                                var option = "<option value='"+ res.list[i].xlid+ "'>"+res.list[i].xlmc+"</option>";

                                $("#xlmc").append(option);
                            };
                            form.render('select');
                        }
                    });
                }
            });
        });
//校验


        form.on('select(xlmc)',function (data) {
            $.ajax({
                url: contextPath+"/road/"+data.value,
                type: "GET",
                contentType:"application/json;charset=utf-8",
                dataType:"json",
                success: function(res) {
                    for(var i in res){
                        $("body").find("[name='"+i+"']").val(eval("res."+i));
                    }

                }
            });
        });


        form.on('submit(new)', function(data){
            console.log(data.field);
            $("input").css("border","");
            $.ajax({
                url: contextPath+"/order",
                type: "POST",
                contentType:"application/json;charset=utf-8",
                data: JSON.stringify(data.field) ,
                dataType:"json",
                success: function(res) {
                    updateSuccess($,layer,res)
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });

</script>
</body>
</html>